package dhu.cst.jnlwt.jiangnan181310209liwanting181310302.tally.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.text.DecimalFormat;
import java.util.List;

import dhu.cst.jnlwt.jiangnan181310209liwanting181310302.tally.R;
import dhu.cst.jnlwt.jiangnan181310209liwanting181310302.tally.database.AccountDao;
import dhu.cst.jnlwt.jiangnan181310209liwanting181310302.tally.entity.AccountBean;

public class DetailAdapter extends BaseAdapter {
    private List<AccountBean> mItems;
    private LayoutInflater mInflater;
    Activity context;

    public DetailAdapter(List<AccountBean> mItems, Activity context) {
        this.mItems = mItems;
        this.context = context;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public Object getItem(int position) {
        return mItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return this.mItems.get(position).getId();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = mInflater.inflate(R.layout.item_listview_detail,null);
        ImageView detail_icon = view.findViewById(R.id.detail_icon);
        TextView detail_category = view.findViewById(R.id.detail_category);
        TextView detail_postscript = view.findViewById(R.id.detail_postscript);
        TextView detail_account = view.findViewById(R.id.detail_account);
        AccountBean accountItem = mItems.get(position);
        AccountDao dbManager = new AccountDao(context);
        detail_icon.setImageResource(dbManager.getIcon(mItems.get(position).getCategory()));
        detail_category.setText(mItems.get(position).getCategory());
        detail_postscript.setText(mItems.get(position).getPostscript());
        detail_account.setText(new DecimalFormat("#0.00").format(accountItem.getAccount()));
        return view;
    }
}
